# Maintainer: Jeroen Ooms <jeroen@berkeley.edu>

_realname=hdf
pkgbase=mingw-w64-${_realname}4
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}4")
pkgver=4.2.13
pkgrel=1
pkgdesc="Legacy HDF4 driver for GDAL (mingw-w64)"
arch=('any')
url='https://support.hdfgroup.org/products/hdf4/'
license=('GPL2')
source=("https://support.hdfgroup.org/ftp/HDF/HDF_Current/src/${_realname}-${pkgver}.tar.gz"
        001-mingw.patch)
sha256sums=('be9813c1dc3712c2df977d4960e1f13f20f447dfa8c3ce53331d610c1f470483'
            '3eaee543f9d1f48a8544b21a2aeda5cb496b9c1dd5f95c15547474db376e30b9')
depends=("${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake")
options=('strip' 'staticlibs')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-mingw.patch
  #sed -i '50s/WIN32/MSVC/' mfhdf/fortran/mfsdf.c
  #sed -i 's/WIN32/MSVC/' mfhdf/libsrc/local_nc.h
  #sed -i 's#<rpc/#<../xdr/#' mfhdf/libsrc/local_nc.h
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_SHARED_LIBS=ON \
    -DHDF4_BUILD_TOOLS=OFF \
    -DHDF4_BUILD_UTILS=ON \
    -DHDF4_BUILD_FORTRAN=ON \
    -DHDF4_NO_PACKAGES=ON \
    -DHDF4_ENABLE_NETCDF=OFF \
    ../${_realname}-${pkgver}

  make

}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"
}
